//
//  InviteInvestedVC.m
//  HengYouCai
//
//  Created by ycgwl on 2017/5/3.
//  Copyright © 2017年 lwj. All rights reserved.
//

#import "InviteInvestedVC.h"
#import "InviteFrientsModel.h"
@interface InviteInvestedVC ()
{
    
    NSInteger _pageNo;
}
@property (nonatomic, retain)NSMutableArray *totalArr;
@property (weak, nonatomic) IBOutlet UILabel *money;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation InviteInvestedVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = Normal_BackColor;
    _pageNo = 1;
    
    _money.attributedText = [NSString stringWithStrArray:@[@"0.00",@"元"] fontArray:@[@25,@14]];
    [self startRefresh];
    self.tableView.mj_footer.hidden = YES;
    [self.view showHUDLoading];
    [self startNetworking];
}
#pragma mark- 刷新
- (void)startRefresh
{
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        _pageNo = 1;
        [self startNetworking];
        
    }];
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        [self startNetworking];
    }];
    
}
#pragma tableviewDatasource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _totalArr.count;
}
#pragma tableviewDelegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InviteRegistedCellID"];
    UILabel *la1 = [cell viewWithTag:1001];
    UILabel *la2 = [cell viewWithTag:1002];
    UILabel *la3 = [cell viewWithTag:1003];
    UILabel *la4 = [cell viewWithTag:1004];
    InviteFrientsModel *model = _totalArr[indexPath.row];
    la1.text = model.tjyh;
    la3.text = model.fljl;
    NSString *time = model.time;
    
    la2.text = [time componentsSeparatedByString:@" "].firstObject;
    la4.text = model.state;
    return cell;
}
- (void)startNetworking
{
    [HYCNetService accountInvateInvestListWithDict:@{@"pageNo":[NSString stringWithFormat:@"%ld",_pageNo],@"pageSize":@"10",} onSuccess:^(NSDictionary *dictResult) {
        //
        [self.view hideHUDLoading:0];
        NSArray *lists = dictResult[@"invateRegList"];
        if (_pageNo==1) {
            [_totalArr removeAllObjects];
            [self.tableView.mj_header endRefreshing];
        }else{
            [self.tableView.mj_footer endRefreshing];
            
        }
        _pageNo++;
        self.tableView.mj_footer.hidden = lists.count<10;
        [self.totalArr addObjectsFromArray:[InviteFrientsModel mj_objectArrayWithKeyValuesArray:lists]];
        [self.tableView reloadData];
        NSString *money = dictResult[@"sumProfitAmt"] ?:@"0.00";
        _money.attributedText = [NSString stringWithStrArray:@[money,@"元"] fontArray:@[@25,@14]];

    } andFailed:^(NSInteger code, NSString *errorMsg) {
        //
        [self.view showHUDFailTips:errorMsg hideDelay:kHUDHideDelay];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
    }];
}
/**
 懒加载
 */
- (NSArray *)totalArr
{
    if (!_totalArr) {
        _totalArr = [NSMutableArray array];
    }
    return _totalArr;
}
@end
